package tests.managers.site;

import java.util.HashMap;
import java.util.Iterator;

import junit.framework.TestCase;

import charazay.tool.cobjects.Player;
import charazay.tool.managers.site.PlayerSiteManager;


public class PlayerSiteManagerTests extends TestCase {
	private PlayerSiteManager playerSiteManager;
	
	public void setUp() {
		playerSiteManager = new PlayerSiteManager(36026);
	}
	
	public void testPlayersURLbuilder() {
		String request_url = "http://www.charazay.com/xml.php?username=titou0612&password=tigrou1978&code=0&id=36026";
		assertEquals(request_url,playerSiteManager.buildURL("titou0612", "tigrou1978", "0", "36026"));
	}
	
	
	public void testRequest() {
		Integer id = new Integer(19901662);
		Player atza = new Player();
		atza.setCharazay_id(id.intValue());
		atza.setFirstName("Jesús");
		atza.setLastName("Andrade");
		
		PlayerSiteManager playermanager = new PlayerSiteManager(36026);
		HashMap tonyPlayers = playermanager.request("titou0612", "tigrou1978");
		
		for (Iterator<Integer> It = tonyPlayers.keySet().iterator();It.hasNext();) {
			Integer next_id = It.next();
			Player skills = (Player) tonyPlayers.get(next_id);
			
			System.out.println(skills.firstName+" "+skills.lastName+" "+skills.age+" "
					+skills.defence+" "
					+skills.dribbling+" "
					+skills.speed+" "
					+skills.footwork+" "
					+skills.passing+" "
					+skills.rebond+" ");
			
		}
		
		Player atzaskills = (Player) tonyPlayers.get(id);
		
		assertEquals(atzaskills.getFirstName(), atza.getFirstName());
		assertEquals(atzaskills.getLastName(), atza.getLastName());
		assertEquals(atzaskills.getCharazay_id(), atza.getCharazay_id());
		
		
	}
}
